﻿package src.cenfun{
	import flash.display.*;
	import flash.geom.*;
	import flash.events.*;
	import flash.filters.*;
	import src.cenfun.*;
	public class Per extends Sprite {
		private var tw:Number;
		private var th:Number;
		public var percent:Number = 0;
		private var a:Number = 0.01;
		public function Per(w:Number, h:Number) {
			setSize(w, h);
			this.visible = false;
		}
		public function setSize(w:Number, h:Number):void {
			tw = w;
			th = h;
		}
		public function start():void {
			percent = 0;
			this.visible = true;
			stage.addEventListener(Event.ENTER_FRAME, changePer);
		}
		public function stop():void {
			stage.removeEventListener(Event.ENTER_FRAME, changePer);
			this.visible = false;
		}
		public function move(tx:Number, ty:Number):void{
			this.x = tx;
			this.y = ty;
		}
		private function changePer(e:Event):void{
			if(percent > 1 || percent < 0){
				a = -a;
			}
			percent += a;
			drawPer();
		}
		private function drawPer():void{
			with(this.graphics){
				clear();
				lineStyle(1, 0xcccccc, 0.3);
				drawRect(-tw/2, 0, tw, -th);
				beginFill(0xeeeeee);
				drawRect(-tw/2, 0, tw, -th*percent);
				endFill();
			}
		}
	}
}